package com.sketch.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sketch.commom.PageResult;
import com.sketch.commom.Result;
import com.sketch.entity.VipPrice;
import com.sketch.entity.dto.VipPriceDTO;
import com.sketch.mapper.VipPriceMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class VipPriceService {
    @Resource
    private VipPriceMapper vipPriceMapper;

    public Result addOrUpdate(VipPriceDTO vipPriceDTO){
        VipPrice vipPrice = new VipPrice();
        BeanUtils.copyProperties(vipPriceDTO,vipPrice);
        if(ObjectUtils.isEmpty(vipPriceDTO.getId())){
            vipPriceMapper.insert(vipPrice);
        }else {
            vipPriceMapper.updateById(vipPrice);
        }

        return Result.success();
    }
    public Result<List<VipPrice>> list(){
        List<VipPrice> vipPrices = vipPriceMapper.selectList(Wrappers.<VipPrice>lambdaQuery().eq(VipPrice::getOnlineStatus,1));
        return Result.success(vipPrices);
    }

    public Result detail(Long id){
        VipPrice vipPrice = vipPriceMapper.selectById(id);
        VipPriceDTO vipPriceDTO = new VipPriceDTO();
        BeanUtils.copyProperties(vipPrice,vipPriceDTO);
        return Result.success().withData(vipPriceDTO);
    }

    public Result delete(Long id){
        vipPriceMapper.deleteById(id);
        return Result.success();
    }
}
